
#include "Knight.h"

Knight::Knight(bool white): Piece(white) {
}

std::string Knight::GetType() const{
   return "knight";
}

std::set<BoardPosition> Knight::GetAllMoves(Board * b, BoardPosition curPos) {
   std::set<BoardPosition> ReturnSet;


   for (int i=-1; i<2; i+=2) {
      BoardPosition pos(curPos.GetRow()+2*i, curPos.GetCol()+i);
      if (pos.IsOnBoard())
         ReturnSet.insert(pos);
      pos = BoardPosition(curPos.GetRow()+2*i, curPos.GetCol()-i);
      if (pos.IsOnBoard())
         ReturnSet.insert(pos);
      pos = BoardPosition(curPos.GetRow()-i, curPos.GetCol()+2*i);
      if (pos.IsOnBoard())
         ReturnSet.insert(pos);
      pos = BoardPosition(curPos.GetRow()+i, curPos.GetCol()+2*i);
      if (pos.IsOnBoard())
         ReturnSet.insert(pos);
   }

   return ReturnSet;
}

std::set<BoardPosition> Knight::GetLegalMoves(Board * b, BoardPosition curPos) {
   std::set<BoardPosition> ReturnSet;


   for (int i=-1; i<2; i+=2) {
      BoardPosition pos(curPos.GetRow()+2*i, curPos.GetCol()+i);
      if (pos.IsOnBoard())
         ReturnSet.insert(pos);
      pos = BoardPosition(curPos.GetRow()+2*i, curPos.GetCol()-i);
      if (pos.IsOnBoard())
         ReturnSet.insert(pos);
      pos = BoardPosition(curPos.GetRow()-i, curPos.GetCol()+2*i);
      if (pos.IsOnBoard())
         ReturnSet.insert(pos);
      pos = BoardPosition(curPos.GetRow()+i, curPos.GetCol()+2*i);
      if (pos.IsOnBoard())
         ReturnSet.insert(pos);
   }

   return ReturnSet;
}
